package com.brillilab.service.core.lab.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brillilab.common.entity.PageVo;
import com.brillilab.dao.mapper.lab.AreaMapper;
import com.brillilab.domain.po.lab.Area;
import com.brillilab.service.core.lab.IAreaService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 地区服务
 *
 * @author wmh
 */
@Service
@Transactional
public class AreaServiceImpl implements IAreaService {

	@Autowired
    private AreaMapper areaMapper;
	
	@Override
	public Area insert(Area area) {
		Integer b = areaMapper.insert(area);
		return b==1 ? area: null;
	}

	@Override
	public boolean deleteById(Long id) {
		Integer b = areaMapper.deleteById(id);
		return b==1 ? true: false;
	}

	@Override
	public boolean updateById(Area area) {
		Integer b = areaMapper.updateById(area);
		return b==1 ? true: false;
	}

	@Override
	public Area selectById(Long id) {
		return areaMapper.selectById(id);
	}
	
	@Override
	public List<Area> selectList(Long parentId) {
		LambdaQueryWrapper<Area> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(Area::getParentId, parentId);
		return areaMapper.selectList(wrapper);
	}

	@Override
	public PageVo<Area> selectPageVo(Page<Area> page, Wrapper<Area> wrapper) {		  
		IPage<Area> iPage = areaMapper.selectPage(page, wrapper);
		return new PageVo<Area>(iPage);
	}

}
